<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>猜大小游戏</title>
    <script src="jquery.min.js"></script>
</head>
<body>
    <button type="button" id="reset">重开一局游戏</button>
    <br>
    <input type="text" id="number">
    <button type="button" id="button">猜</button>
    <br>
    已经猜的次数:<span id="count">0</span>
    <br>
    结果:<span id="result"></span>
    <script>
        $(function(){
            var count = 0;
            var guessNumber = Math.floor(Math.random()*100)+1;
            console.log(guessNumber);
            $("#button").click(function(){
            count++;
            $("#count").text(count);
            var userGuess = parseInt($("#number").val());
            if(userGuess == guessNumber){
                $("#result").text("猜对了")
            }else if(userGuess < guessNumber){
                $("#result").text("猜大了")
            }else{
                $("#result").text("猜小了")
            }
            });
        });
        $("#reset").click(function(){
            guessNumber = Math.floor(Math.random()*100)+1;
            count = 0;
            $("#count").text(count);
            $("#result").text("");
            $("#number").val("");
        });
        
    </script>
</body>
</html>